from .base import Base
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer
from sqlalchemy.databases.mysql import MSNumeric, MSFloat
from sqlalchemy.orm import relation

__all__ = ["Money"]

class Money(Base):
    __tablename__ = "moneys"
    
    id = Column(Integer, primary_key=True)
    amount = Column(MSFloat(scale=4), server_default="0", nullable=False)
    currency_id = Column(Integer, ForeignKey('currencies.id'), nullable=False)
    
    currency = relation('Currency')
    
    def __init__(self, amount, currency):
        self.amount = amount
        self.currency = currency

    def getData(self):
        class Money:
            _amount = self.amount
            _currency = self.currency.code
        return Money
        
    def __repr__(self):
        return "<Money('%s', '%s')>" % self.amount, self.currency